<template>
	<view class="details">
		<view class="details-top">
			<view class="top-1">
				<view>{{title}}</view>
				<view class="seeLise" @click="seeLise" v-if="showSee">
					查看
				</view>
			</view>
			<view class="top-2">
				<view class="top-left">
					{{list.name}}
				</view>
				<view class="top-right" v-if="type==1">
					￥{{list.price}}元
				</view>
				<view class="top-right" v-else>
					总需：{{list.num}}株
				</view>
			</view>
		</view>
		<view class="content">
			<view class="con-title" v-if="showTitle">
				规格参数
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in list.specs_config" :key="index" v-if="item.value!=''">
					{{item.name}}：{{item.value}}{{item.unit}}
				</view>

			</view>
			<view class="jianjie">
				<view class="">
					简介：{{list.introduction}}
				</view>

			</view>
			<view class="content-bottom">
				<view class="dizhi">
					地址：{{showAddress?list.address:'****************'}}
				</view>
				<view class="dianhua">
					<view class="left-details">
						电话号码:
					</view>
					<view class="right-details find">
						<text @click="goTel()">{{phone||'****************'}}</text><text class="blue" @click="telPhone"
							style="margin-left: 20px;">查看号码</text>
					</view>
				</view>
			</view>
		</view>
		<view class="img-bottom">
			<view>图片展示：</view>
			<image :src="item" mode="widthFix" v-for="item in list.imgs"></image>
		</view>
		<bottomShow :showPop="showBottom" :title="bottomTitle" :tip="bottomTip" @refuse="refuse" @submit="subTel">
		</bottomShow>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		getPhone
	} from '@/request/api.js'
	import bottomShow from '@/components/common/bottomShow.vue'
	export default {
		components: {
			// vvSelectArea
			bottomShow
		},
		data() {
			return {
				list: [],
				form: {
					type: 1,
					id: '',
				},
				phone: '',
				title: '',
				type: 1,
				showAddress: false,
				showTitle: false,
				showBottom: false,
				bottomTitle: '',
				bottomTip: '',
				showSee: false
			};
		},
		onLoad(e) {
			let data = JSON.parse(e.data)
			if (e.type == 1) {
				this.showSee = JSON.parse(e.showSee)
			}
			// console.log(this.showSee,'565456')
			this.list = data
			this.title = e.type == 1 ? "供应列表" : "求购列表"
			this.form.type = e.type
			this.type = e.type
			this.form.id = data.id
			this.list.specs_config.forEach(item => {
				if (item.value == '') {
					this.showTitle = false
				} else {
					this.showTitle = true
				}
			})
			// console.log(this.list)
		},
		methods: {
			seeLise() {
				console.log(this.list.user_id,'this.type')
				// uni.navigateTo({
				// 	url: '/my_pages/my_supply/supply?user_id=' + this.list.user_id
				// })
				if(this.type ==2){ //
					uni.navigateTo({
						url: '/my_pages/myWant/myWant?myType=1'
					})
				}else{
					uni.navigateTo({
						url: '/my_pages/my_supply/supply?user_id='+this.list.user_id
					})
				}
			},
			goTel() {
				uni.makePhoneCall({
					phoneNumber: this.phone,
					success(res) {
						// cconsole.log('拨打电话成功', res);
					},
					fail(err) {
						console.log('拨打电话失败', err);
					}
				})
			},
			refuse() {
				this.showBottom = false
			},
			telPhone() {
				if (this.phone == '') {
					this.bottomTitle = '查看电话'
					this.bottomTip = '提示：普通会员查看电话需要充值积分，黄金会员或者钻石会员查看电话免费，自己查看自己电话免费！'
					this.showBottom = true
				} else {

				}

			},
			subTel() {
				getPhone(this.form).then(res => {
					if (res.code == 1) {
						this.phone = res.data.phone
						this.showAddress = true
						this.$refs.uToast.show({
							type: 'success',
							title: '获取电话成功',
							message: "获取电话成功",
						})
					}
				})
				this.showBottom = false
			}
		}
	}
</script>
<style>
	page {
		background-color: #f6f6f6;
	}
</style>
<style lang="scss" scoped>
	.details {
		font-size: 26rpx;

		.img-bottom {
			padding: 20rpx;
			margin-bottom: 20px;
			display: flex;
			flex-direction: column;

			image {
				margin-top: 15rpx;
				width: 100%;
				border-radius: 15rpx
			}
		}

		.top-1 {
			display: flex;
			justify-content: space-between;

			.seeLise {
				color: #fff;
				background-color: #00C777;
				padding: 8rpx 18rpx;
				border-radius: 26rpx;
			}
		}

		.content {
			display: flex;
			flex-direction: column;
			padding: 0 20rpx;
			background: #fff;
			margin-top: 15px;
			padding-top: 15rpx;

			.con-title {
				color: #979797;
				margin-top: 15px;
			}

			.jianjie {
				border: 1px solid #C9C9C9;
				color: #979797;
				// width: 94%;
				padding: 10rpx 10rpx;
				// overflow: hidden;
				// white-space: nowrap;
				// text-overflow: ellipsis;
				// -o-text-overflow: ellipsis;
			}

			.content-bottom {
				margin: 15px 0;

				.dizhi {
					margin-bottom: 10rpx;
				}

				.dianhua {
					color: #00C777;
					display: flex;
					margin: 15rpx 0;

					.left-details {
						width: 80px;
					}

					.right-details {
						flex: 1;

					}

					.find {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-right: 20rpx;
					}
				}
			}

			.list {
				color: #00C777;
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				justify-content: space-between;

				.item {
					// width: 33.33%;
					text-align: center;
					width: 31%;
					text-align: center;
					padding: 18rpx 0;
					// margin-right: 2%;
					margin-bottom: 15rpx;
					margin-top: 15px;
					border: 1px solid #00C777;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					-o-text-overflow: ellipsis;
				}
			}

		}

		.details-top {
			display: flex;
			background-color: #fff;
			flex-direction: column;
			padding: 0 20rpx;

			.top-1 {
				color: #00C777;
				margin: 22rpx 0px;
				border-bottom: 1px solid #E2E2E2;
				padding-bottom: 25rpx;
			}

			.top-2 {
				display: flex;

				.top-left {
					flex: 1;
				}

				.top-right {
					width: 100px;
					padding-bottom: 20px;
				}
			}
		}
	}
</style>
